package com.example.controller;

import com.example.pojo.PageResult;
import com.example.pojo.Result;
import com.example.pojo.Student;
import com.example.pojo.StudentQueryParam;
import com.example.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: Sun
 * @Date: 2025/9/22 - 09 - 22 - 18:46
 * @Description: com.example.controller
 */
@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController{
    @Autowired
    private StudentService studentService;
    @GetMapping
    public Result list(StudentQueryParam studentQueryParam){
        log.info("查询学生列表");
        PageResult<Student> pageResult = studentService.list(studentQueryParam);
        return Result.success(pageResult);
     }

     @DeleteMapping("/{ids}")
     public Result delete(@PathVariable List<Integer> ids){
         log.info("删除学生信息");
         studentService.delete(ids);
         return Result.success();
     }
     @PostMapping
    public Result insert(@RequestBody Student student){
         log.info("添加学生信息");
         studentService.insert(student);
         return Result.success();
     }
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){

        log.info("根据id查询班级");
         Student student = studentService.getById(id);
        return Result.success(student);
    }
    @PutMapping
    public Result update(@RequestBody Student student){


        log.info("修改学生信息");
        studentService.updateById(student);
        return Result.success();}
    @PutMapping("/violation/{id}/{score}")
    public Result violation(@PathVariable Integer id, @PathVariable Integer score) {
        log.info("学员违纪处理: id={}, score={}", id, score);
        studentService.violation(id, score);
        return Result.success();
    }
}

